package cn.chengpengper.seckill.goods.application.builder;


import cn.chengpengper.seckill.common.builder.SeckillCommonBuilder;
import cn.chengpengper.seckill.common.code.HttpCode;
import cn.chengpengper.seckill.common.exception.SeckillException;
import cn.chengpengper.seckill.common.model.dto.SeckillGoodsDTO;
import cn.chengpengper.seckill.common.utils.bean.BeanUtil;
import cn.chengpengper.seckill.goods.application.command.SeckillGoodsCommand;
import cn.chengpengper.seckill.goods.model.entity.SeckillGoods;

import java.util.Objects;

/**
 * @author chengpeng.hu
 */
public class SeckillGoodsBuilder extends SeckillCommonBuilder {

    public static SeckillGoods toSeckillGoods(SeckillGoodsCommand seckillGoodsCommand) {
        if (Objects.isNull(seckillGoodsCommand)) {
            throw new SeckillException(HttpCode.PARAMS_INVALID);
        }
        SeckillGoods seckillGoods = new SeckillGoods();
        BeanUtil.copyProperties(seckillGoodsCommand, seckillGoods);
        return seckillGoods;
    }

    public static SeckillGoodsDTO toSeckillGoodsDTO(SeckillGoods seckillGoods) {
        if (Objects.isNull(seckillGoods)) {
            throw new SeckillException(HttpCode.PARAMS_INVALID);
        }
        SeckillGoodsDTO seckillGoodsDTO = new SeckillGoodsDTO();
        BeanUtil.copyProperties(seckillGoods, seckillGoodsDTO);
        return seckillGoodsDTO;
    }

}
